package com.liz.test_old;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Text_insert {
    public static void main(String[] args) {
        String jdbcdrive = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/bylianxi";
        String username = "root";
        String userpassword = "Au7989l";
        Connection conn = null;
        Statement statement = null;
        try {
            Class.forName(jdbcdrive);
            conn = DriverManager.getConnection(url,username,userpassword);
            String sql = "insert into emp (ename,sal) values ('lili',9000)";
            statement = conn.createStatement();
            int num = statement.executeUpdate(sql);
            if (num>0){
                System.out.println("成功");

            }else {
                System.out.println("失败");
            }
//            System.out.println(conn);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally{
            try {
                statement.close();
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }

        }
    }
}
